home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 4_12.lha / 4_12 / 4_12d.c < prev    next >
Text File  |  1993-08-08  |  912b  |  52 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. include <stream.h>
  6. include <stdlib.h>
  7.  
  8. ain(int argc, char **argv)
  9.  
  10.    if (argc != 3)
  11. {
  12. cerr << "usage: " << argv[0] <<
  13.     " period char-index";
  14. return 1;
  15. }
  16.  
  17.    int period = atoi(argv[1]);
  18.    int char_index = atoi(argv[2]);
  19.    if ((char_index >= period) || (period <= 0) ||
  20. (char_index < 0))
  21. {
  22. cerr << "usage: " << argv[0] <<
  23.     " period char-index\n" <<
  24.     "\t0 < char-index < period\n";
  25. return 1;
  26. }
  27.  
  28.    short count[0400];
  29.    for (int i = 0; i < 0400; i++)
  30. count[i] = 0;
  31.  
  32.    long total = 0;
  33.    unsigned char c;
  34.    for (i = 0; cin.get(c); i++)
  35. {
  36. if (i == period)
  37.     i = 0;
  38.  
  39. if (i == char_index)
  40.     {
  41.     count[c]++;
  42.     total++;
  43.     }
  44. }
  45.  
  46.    for (i = 0; i < 0400; i++)
  47. cout << i << "\t" << count[i] <<  "\t" <<
  48.     (100.0 * count[i] / total) << "\n";
  49.  
  50.    return 0;
  51.  
  52.